//package com.zws.cucumber.plugin;
//
//import com.zws.cucumber.ZwsUtils;
//import com.zws.cucumber.plugin.procedure.ZwsProcedurePluginImpl;
//import com.zws.cucumber.plugin.snapshot.ZwsSnapshotPluginImpl;
//import com.zws.cucumber.util.colorfullog.ZwsColorfulLogger;
//import io.cucumber.core.eventbus.AbstractEventPublisher;
//import io.cucumber.core.eventbus.EventBus;
//import io.cucumber.core.runtime.SynchronizedEventBus;
//import io.cucumber.plugin.EventListener;
//import io.cucumber.plugin.event.*;
//import org.apache.commons.lang3.SystemUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
///**
// * author: zws
// */
//public class ZwsProcedurePlugin implements EventListener {
//
//    private static final org.slf4j.Logger logger = ZwsColorfulLogger.of(ZwsProcedurePlugin.class);
//
//    public static EventBus eventBus;
//
////    private static PrettyFormatter prettyFormatter = new PrettyFormatter(new BufferedOutputStream(System.out));
//
//    @Override
//    public void setEventPublisher(EventPublisher publisher) {
//        eventBus = (EventBus) publisher;
//
//        initProcedurePlugin(publisher);
//        initOptimizationPlugin(publisher);
//
//        EventBus delegate = ZwsUtils.getFieldValue(SynchronizedEventBus.class, "delegate", eventBus);
//        Map<Class<? extends Event>, List<EventHandler>> handlers = ZwsUtils.getFieldValue(AbstractEventPublisher.class, "handlers", delegate);
//        // first step to change the status to passed if it is skipped
//        List<EventHandler> handlerList = handlers.computeIfAbsent(TestStepFinished.class, k -> new ArrayList<>());
//        handlerList.add(0, ZwsProcedurePluginImpl::handleTestCaseFinished);
//    }
//
//    public void initProcedurePlugin(EventPublisher publisher) {
//        publisher.registerHandlerFor(TestCaseStarted.class, ZwsProcedurePluginImpl::handleTestCaseStarted);
//    }
//
//    public void initOptimizationPlugin(EventPublisher publisher) {
//        if (!SystemUtils.IS_OS_WINDOWS) {
//            logger.info("<c>disable cucumber ct optimization globally since it only supported in windows platform now</c>");
//            return;
//        }
//        // disable default due to lots of people occurring problem
//        if ("true".equalsIgnoreCase(System.getProperty("enableCucumberCtOptimization"))) {
//            ZwsSnapshotPluginImpl.setGlobalEnable(true);
//            logger.info("<c>enable cucumber ct optimization globally</c>");
//        } else {
//            ZwsSnapshotPluginImpl.setGlobalEnable(false);
//            logger.info("<c>disable cucumber ct optimization globally</c>");
//        }
//        publisher.registerHandlerFor(TestCaseStarted.class, ZwsSnapshotPluginImpl::handleTestCaseStarted);
//    }
//
////    private static void printTestStepFinishedEvent(TestStepFinished event) {
////        try {
////            Method method = ReflectionUtils.findMethod(PrettyFormatter.class, "printStep", TestStepFinished.class);
////            method.setAccessible(true);
////            method.invoke(prettyFormatter, event);
////        } catch (Exception e) {
////            throw new RuntimeException(e);
////        }
////    }
//
//}
